﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#if !NETCOREAPP
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
    using System.Web.Mvc.Html;

#endif

#if NETCOREAPP
using Microsoft.AspNetCore.Mvc.Rendering;
using Kugar.Core.Web;
#endif
using Kugar.MVC.MobileUI.WeUI.Helpers;

namespace Kugar.MVC.MobileUI.WeUI.PageControls.PageForm
{
    public class PageForm_Slider: PageForm_FieldBase
    {
        private bool _displayValueBox = false;
        private int _min = 0;
        private int _max = 100;
        private int _value = 0;

        public PageForm_Slider(ViewContext viewContext) : base(viewContext)
        {
            this.Css("weui-cells_slider-box");
        }

        public PageForm_Slider ValueBox(bool displayValueBox)
        {
            _displayValueBox = displayValueBox;

            return this;
        }

        public PageForm_Slider Max(int value)
        {
            _max = value;

            return this;
        }

        public PageForm_Slider Min(int value)
        {
            _min = value;

            return this;
        }

        public PageForm_Slider Value(int value)
        {
            _value = value;

            return this;
        }

        public override MvcHtmlString Render()
        {
            if (!string.IsNullOrWhiteSpace(_label))
            {
                ViewContext.Writer.WriteLine($"<div class=\"weui-cells__title\">{_label}</div>");
            }

            return base.Render();
        }

        protected override void RenderBody()
        {
            /*
             <div class="weui-slider-box" id="slider2">
			    <div class="weui-slider">
			      <div id="sliderInner" class="weui-slider__inner">
				    <div id="sliderTrack" style="width: 55%;" class="weui-slider__track"></div>
				    <div id="sliderHandler" style="left: 55%;" class="weui-slider__handler"></div>
			      </div>
			    </div>
			    <div id="sliderValue" class="weui-slider-box__value">55</div>
		      </div>
             */

            if (_displayValueBox)
            {
                this.Css("weui-slider-box");
            }

            ViewContext.Writer.WriteLine($"<div {_attrs} data-min=\"{_min}\" data-max=\"{_max}\">");
            ViewContext.Writer.WriteLine("<div class=\"weui-slider\">");

            ViewContext.Writer.WriteLine("<div class=\"weui-slider__inner\">");

            ViewContext.Writer.WriteLine($"<div style=\"width: {(_value/_max)}%;\" class=\"weui-slider__track\"></div>");
            ViewContext.Writer.WriteLine($"<div style=\"left: {(_value / _max)}%;\" class=\"weui-slider__handler\"></div>");

            ViewContext.Writer.WriteLine("</div> <!-- end slider__inner -->");

            ViewContext.Writer.WriteLine("</div> <!-- end weui-slider -->");

            if (_displayValueBox)
            {
                ViewContext.Writer.WriteLine($"<div class=\"weui-slider-box__value\">{(int)(_value / _max)}</div>");
            }
            
            ViewContext.Writer.WriteLine($"<input name=\"{_name}\"  value=\"{(_value / _max)}\" type=\"hidden\" />");
            ViewContext.Writer.WriteLine("</div> <!-- end slider -->");
        }
    }
}